using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Simnova.Collaborate.Presenter;
using Simnova.Collaborate.View;

public partial class _TimeHome : System.Web.UI.Page, ILogin
{
    private LoginPresenter _loginPresenter;
    private int _userId;
    private UserPresenter _userPresenter;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            _loginPresenter = new LoginPresenter(this);
            LoginPanel.Visible = true;
        }
        else
        {
            _userId = int.Parse(Session["UserId"].ToString());
            _userPresenter = new UserPresenter(_userId);
            LoggedInPanel.Visible = true;
            //ScreenName.Text = _userPresenter.ScreenName;
            TotalHours.Text = "0";
        }

    }

    protected void LoginButton_Click(object sender, EventArgs e)
    {
        int userId = 0;
        try
        {
            LoginValidator.ErrorMessage = "";
            userId = _loginPresenter.Login();

        }
        catch (Exception ex)
        {
            if (ex.Message == "Login Failed")
            {
                LoginValidator.ErrorMessage = "Login Failed";
                LoginValidator.Enabled = true;
            }
            else
            {
                throw;
            }
            return;
        }
        Session["UserId"] = userId;
        _userId = userId;
        Response.Redirect(@"~\TimeHome.aspx", true);
    }

    #region ILogin Members

    string ILogin.EmailAddress
    {
        get
        {
            return EmailAddressTextBox.Text;
        }
        set
        {
            EmailAddressTextBox.Text = value;
        }
    }

    string ILogin.Password
    {
        get
        {
            return PasswordTextBox.Text;
        }
        set
        {
            PasswordTextBox.Text = value;
        }
    }

    #endregion
}
